<template>
	<view>
		<view @touchmove.prevent.stop class="shade" v-if="is_admin == 0">
			<view class="apply_title">抱歉！您不是超级管理员，无法浏览当前页面</view>
		</view>
		
		<uni-search-bar :radius="100" :clearButton="'auto'" ></uni-search-bar>
		
		<view>
			<view class="staff">
				<view class="staff-em"></view>
				<view class="staff-text">管理员申请列表</view>
			</view>
			<view v-for="(item, index) in apply_list" :key="index">
				<view class="d-flex a-center mt-1 j-sb pl-3 pr-3">
					<view class="d-flex a-center ">
						<view style="width: 300rpx; margin-right: 30rpx;">
							<view><span style="color: #777;">姓名：</span>{{ item.name }}</view>
							<view><span style="color: #777;">电话：</span>{{ item.tel }}</view>
						</view>
					</view>
			
					<view @click="tongguo(index, item.user_id)" :class="item.status == 0 ? 'no-pass' : 'pass'">
						{{ item.status ? '已审核' : '点击审核' }}
					</view>
				</view>
				<divider />
			</view>
		</view>
		<uni-load-more :status="status" style="margin-bottom: 140rpx;" />
		<image class="goTop" src="http://www.mescroll.com/img/mescroll-totop.png?v=1" v-show="isshow" @click="goTop"></image>
	</view>
</template>

<script>
	import uniLoadMore from '../../components/common/uni-load-more.vue'
	import uniSearchBar from '@/components/uni-search-bar/uni-search-bar.vue'
	export default {
		components: {
			uniLoadMore,
			uniSearchBar,
		},
		data() {
			return {
				status: 'more',
				isshow: false,
				apply_list: [],
				page: 1,
				is_admin: 1,
			};
		},
		onLoad() {
			this.$comm.appLogin(user_info=>{
				this.get_apply_list()
				console.log(user_info)
			})
		},
		onShow() {
		},
		onPageScroll(e) {
			if (e.scrollTop > 500) {
				this.isshow = true
			} else {
				this.isshow = false
			}
		},
		onPullDownRefresh() {
			this.page = 1;
			this.status = 'more';
			this.apply_list = [];
			this.get_apply_list()
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {
			tongguo(index, user_id) {
				// console.log(this.apply_list[index],user_id)
				if (this.apply_list[index].status == 1) {
					uni.showToast({
						title: '已审核，请勿重复点击',
						icon: 'none',
						duration: 2000
					})
					return
				}
				let data  = {
					user_id: user_id,
					check: 1,
				}
				this.$comm.request({
					url: 'api/apply_check',
					method: 'POST',
					data: data,
					success: res => {
						console.log(res,'tongguo')
						if (res.data.code != 200){
							uni.showToast({
								title: res.data.msg,
								icon: "none"
							});
							return
						}
						this.$set(this.apply_list[index],'status',1)
						uni.showToast({
							title: '审核成功！',
							icon: "success",
							duration: 2000,
						});
					}
				});
			},
			
			get_apply_list() {
				if (this.status == 'nomore') return
				this.$comm.request({
					url: 'api/apply_list',
					method: 'GET',
					data: {
						page: this.page++
					},
					success: (res) => {
						if (res.data.code == 202) {
							this.is_admin = 0
							this.status = 'nomore'
							return
						}
						console.log(res, 'get_apply_list')
						let list = res.data.result.list
						this.apply_list = this.apply_list.concat(list)
						if (list.length < 10) this.status = 'nomore'
					}
				})
			},
			
			goTop() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 0
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import '@/common/main.css';
	@import  '@/common/zcm-main.css';
	
	page {
		// padding: 0 30rpx;
		font-size: 30rpx;
		background-color: #F5F5F5;
	}
	
	.shade {
			position: fixed;
			height: 100vh;
			z-index: 1000;
			background-color: rgba(0, 0, 0, .6);
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
		
			.apply_title {
				color: #ffffff;
				font-size: 35rpx;
				margin-bottom: 20rpx;
			}
		
			.btn{
				background-color:#475dfc;color: #ffffff;font-size: 30rpx;padding: 10rpx 30rpx;border-radius: 50rpx;	
			}
		}
	
	.bottom-box {
		display: flex; align-items: center; justify-content: space-around; position: fixed; bottom: 0; width: 750rpx; background-color: #fff; height: 100rpx; border-top: 1px solid #eee; font-size: 24rpx;
		
		.admin-box {
			display: flex;flex-direction: column; align-items: center;
			
			.admin-img {
				height: 60rpx; width: 60rpx;
			}
		}
	}
	
	.staff {
		padding: 0 30rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		// margin-left: 50rpx;
		margin-top: 10rpx;
	
		.staff-em {
			height: 35rpx;
			width: 10rpx;
			background-color: #475dfc;
			border-radius: 50rpx;
		}
	
		.staff-text {
			font-weight: bold;
			margin-left: 10rpx;
		}
	}
	
	.inite {
		font-size: 26rpx;
		color: #ffffff;
		width: 70rpx;
		// height: 40rpx;
		// line-height: 1.7;
		text-align: right;
		padding: 5rpx;
		background-color: #475dfc;
		border-radius: 50rpx 0rpx 0rpx 50rpx;
	}
	
	.inite-count {
		font-size: 26rpx;
		width: 70rpx;
		padding: 5rpx;
		color: #475dfc;
		text-align: center;
		border: solid 1rpx #475dfc;
		border-radius: 0rpx 50rpx 50rpx 0rpx;
	}
	
	@mixin pass1 {
		width: 120rpx;
		// margin-left: 50rpx;
		font-size: 25rpx;
		color: #ffffff;
		padding: 6rpx 10rpx 6rpx 10rpx;
		text-align: center;
		border-radius: 50rpx;
	}
	
	.no-pass {
		@include pass1;
		background-color: #A40000;
	}
	
	.pass {
		@include pass1;
		background-color: #5fb256;
	}
</style>
